// pages/person/person.js
const app = getApp()
const wh = require("../../utils/wh.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    auth_modal: false, // 授权窗口
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    avatar: '../../img/face.png',
    userData:[],
    imgUrls: [
      { id: 1, img: '../../img/ywc.png',tilte:'已完成' },
      { id: 2, img: '../../img/dfk.png', tilte: '待付款'},
      { id: 3, img: '../../img/dwc.png', tilte: '待完成'},
      { id: 4, img: '../../img/shtk.png', tilte: '售后/退款'},
    ],
    red:''
  },
  order(e) {
    let idx = e.currentTarget.dataset.idx
    wx.navigateTo({
      url: '../order/order?c=' + idx,
    })
  },
  // 点击我要入驻
  enter(){
    let that = this;
    wh.Post('/api/mall.shop/status', {}, function(res){
      console.log(res)
      if (res.status == 0) {
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000,
        })
      }
      else {
        wx.navigateTo({
          url: 'enter',
        })
      };
    });
  },
  // 小红点
  red(){
    let that = this;
    wh.Post('/api/mall.order/total', {}, function(res){
      console.log(res)
      that.setData({

        red:res
      })
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.red()
    // 判断是用户已授权
    let employId = wx.getStorageSync('employId');
    if (!employId || employId == '') {
      app.employIdCallback = employId => {
        if (employId != '') {
          let userData = wx.getStorageSync('W_Userinfo')
          this.setData({
            userData: JSON.parse(userData)
          });
        }
      }
    } else {
      let userData = wx.getStorageSync('W_Userinfo')
      this.setData({
        userData: JSON.parse(userData)
      });
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.app_auth(this)
    // this.selectComponent("#mobile_auth").onCheckMobile(has)
    // 判断是用户已授权
    let employId = wx.getStorageSync('employId');
    if (!employId || employId == '') {
      app.employIdCallback = employId => {
        if (employId != '') {
          let userData = wx.getStorageSync('W_Userinfo')
          this.setData({
            userData: JSON.parse(userData)
          });
        }
      }
    } else {
      let userData = wx.getStorageSync('W_Userinfo')
      this.setData({
        userData: JSON.parse(userData)
      });
    }
    this.selectComponent("#auth").onCheck()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})